package net.pulseproject.router.config.parser;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LineFilter {

	private static final Log LOG = LogFactory.getLog(LineFilter.class);
	
	private static final String COMMENT_SIGN = "#";
	
	
	public final Collection<String> filterValidLines(final String[] rawConfigLines) {
		LOG.trace("filterValidLines(rawConfigLines)");
		final List<String> result = new LinkedList<String>();
		
		for (final String line : rawConfigLines) {
			if(this.validateLine(line.trim()) == true) {
				result.add(line);
			}
		}
		
		return result;
	}
	
	public boolean validateLine(final String line) {
		if(line.isEmpty() == true) {
			LOG.trace("dropping empty line.");
			return false;
		}
		
		if(line.startsWith(COMMENT_SIGN) == true) {
			LOG.trace("dropping outcommented line: [" + line + "]");
			return false;
		}
		
		return true;
	}

}
